package cruncher;

import ilog.concert.IloCopyManager;
import ilog.concert.IloException;
import ilog.concert.IloLPMatrix;
import ilog.concert.IloObjective;
import ilog.concert.IloRange;
import ilog.cplex.IloCplex;

public class CPLEXUtils {
	public IloCplex cplex;

	public CPLEXUtils(IloCplex cplex) {
		this.cplex = cplex;
	}
	
	public static IloCplex clone(IloCplex cplex) 
	{ 
		IloCplex result = null;
		try {
			IloCplex cplex_orig = cplex; 
			IloLPMatrix lp = (IloLPMatrix)cplex_orig.LPMatrixIterator().next();
			IloCopyManager cm = new IloCopyManager(cplex_orig); 
		
			result = new IloCplex(); 
			//makeCopy not implemented by C++
			IloObjective obj = (IloObjective)cplex_orig.getObjective().makeCopy(cm); 
			result.add(obj); 
	
			for(int r=0;r < lp.getRanges().length ; r++)
				{
					//System.Console.WriteLine(lp.Ranges[r].ToString()); 
					IloRange temp = (IloRange)lp.getRange(r).makeCopy(cm); 
					result.add(temp);
				}
			} catch (IloException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		return result;
		}
}